﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JobOffersBrowser.Helpers;

namespace JobOffersBrowser.ViewModels
{
    public class StatistictsViewModel
    {
        public StatistictsViewModel()
        {
            monthData = new Month[12];
            var offers = ViewModelsHelper.GetAllOffers();

            for (int i = 0; i < MonthData.Length; i++)
            {
                MonthData[i] = new Month()
                {
                    MonthName = GetMonthName(i + 1),
                    Count = offers.Where(o => o.PublishDate.Month == i).ToList().Count
                };
            }
        }

        private string GetMonthName(int i)
        {
            string month = null;
            switch(i)
            {
                case 1:
                    month = "January";
                    break;
                case 2:
                    month = "February";
                    break;
                case 3:
                    month = "March";
                    break;
                case 4:
                    month = "April";
                    break;
                case 5:
                    month = "May";
                    break;
                case 6:
                    month = "June";
                    break;
                case 7:
                    month = "July";
                    break;
                case 8:
                    month = "August";
                    break;
                case 9:
                    month = "September";
                    break;
                case 10:
                    month = "October";
                    break;
                case 11:
                    month = "November";
                    break;
                case 12:
                    month = "December";
                    break;
                default:
                    month = "No such month";
                    break;
            }

            return month;
        }

        public Month[] MonthData
        {
            get
            {
                return monthData;
            }
            set
            {
                monthData = value;
            }
        }

        public class Month
        {
            public string MonthName { get; set; }
            public int Count { get; set; }
        }

        private Month[] monthData;
    }
}